package com.survey.demo.ui.adapter;


import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.survey.demo.R;
import com.survey.demo.app.AppApplication;
import com.survey.demo.http.bean.CommonTestDataEntity;
import com.survey.demo.http.glide.GlideApp;
import com.survey.demo.widget.BannderImageHolder;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;


/**
 * @author: CWB(9093694 @ qq.com)
 * @date: 2020/6/18 11:01
 * Tip:--
 */
public class HomeShopingBannerAdapter extends BannerAdapter<CommonTestDataEntity, BannderImageHolder> {

    public HomeShopingBannerAdapter(List<CommonTestDataEntity> mDatas) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDatas);
    }

    //更新数据
    public void updateData(List<CommonTestDataEntity> data) {
        //这里的代码自己发挥，比如如下的写法等等
        mDatas.clear();
        mDatas.addAll(data);
        notifyDataSetChanged();
    }


    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public BannderImageHolder onCreateHolder(ViewGroup parent, int viewType) {

        //使用自定义image title 布局
        return new BannderImageHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.banner_image_title, parent, false));
    }

    @Override
    public void onBindView(BannderImageHolder holder, CommonTestDataEntity data, int position, int size) {
        holder.imageView.setImageResource(data.imageRes);
        holder.title.setText(data.title);
//        GlideApp.with(AppApplication.context)
//                .load(data.imageUrl)
//                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
//                .into(holder.imageView);
    }
}
